AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

function ENT:Initialize()

	self.Entity:SetModel( "models/props_c17/pipe_cap003.mdl" )
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS )
	self.Entity:SetKeyValue("rendermode", "10")
	self.Entity:SetAngles(self.Entity:GetAngles())
	self.Entity.health = 0
	self.Entity.CreateTime = CurTime() 	
	local phys = self.Entity:GetPhysicsObject()
		if (phys:IsValid()) then
				
			phys:Wake()
			
			phys:EnableGravity(false)
			
			phys:EnableDrag(false)
				
			
		end
	self.timer = CurTime()+0.05
		
	end


function ENT:OnTakeDamage( dmginfo )
	self.Entity:TakePhysicsDamage( dmginfo )
end

function ENT:PhysicsCollide( data, physobj )
if data.HitEntity:GetMoveType() == 6 then
data.HitEntity:GetPhysicsObject():ApplyForceCenter(data.OurOldVelocity*1000000000*data.HitEntity:GetPhysicsObject():GetMass())
end
util.BlastDamage(self.Entity,self.Entity,self.Entity:GetPos(),500,30)
for k,v in pairs(ents.FindInSphere(self.Entity:GetPos(),500)) do
empattack(self.Entity:GetVar("Owner"),v,20)
end
doempspark(self.Entity:GetPos(),5)
doempspark(self.Entity:GetPos(),5)
doempspark(self.Entity:GetPos(),5)
doempspark(self.Entity:GetPos(),5)
self.Entity:Remove()
end

function ENT:Use( activator )
	--generic comment
end


function ENT:Think()

	local phys = self.Entity:GetPhysicsObject()
	if ( phys:IsValid() ) then
		if self.Entity.CreateTime + 0.5 < CurTime() then
			phys:ApplyForceCenter(self.Entity:GetForward() * 1000)
			doempspark(self.Entity:GetPos(),1)
		end
	end
	if self.Entity.CreateTime +20 < CurTime() then
	util.BlastDamage(self.Entity,self.Entity,self.Entity:GetPos(),500,30)
	for k,v in pairs(ents.FindInSphere(self.Entity:GetPos(),500)) do
	empattack(self.Entity:GetVar("Owner"),v,20)
	end
	doempspark(self.Entity:GetPos(),10)
	doempspark(self.Entity:GetPos(),10)
	doempspark(self.Entity:GetPos(),10)
	doempspark(self.Entity:GetPos(),10)
	end
	
	

if self.timer > CurTime() then return end
self.timer = CurTime() + 0.05
doempspark(self.Entity:GetPos(),1)
end
